<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            margin: 200px;
        }

        span {
            display: inline-block;
            width: 40px;
            height: 40px;
            background-color: #333;
            font-size: 20px;
            color: #fff;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>
<body>
    <div>
        <span class="hour">1</span>
        <span class="minute">2</span>
        <span class="second">3</span>
    </div>
    <script>
        /*
          比如：从五点，到四点半，相差的时间换算为时分秒，
          每一秒计算一次，刷新到 span

        */
        var hour = document.querySelector('.hour');
        var minute = document.querySelector('.minute');
        var second = document.querySelector('.second');

        function countDown(time) {
            // 转化为时间戳
            var inputTime = time.valueOf();
            // 当前时间的时间戳
            var nowTime = +new Date();
            // 时间差 ms
            var sub = inputTime - nowTime;
            // 转化为 s
            sub = sub / 1000;
            // 转化为 整型
            sub = parseInt(sub);
            // console.log(sub);

            d = sub / 60 / 60 / 24; //计算天数
            h = sub / 60 / 60 % 24; // 计算小时
            m = sub / 60 % 60;	// 计算分数
            s = sub % 60;	//计算当前秒数 
            h = parseInt(h);
            m = parseInt(m);
            s = parseInt(s);
            // 小于 10 补零
            h = h < 10 ? "0" + h : h;
            m = m < 10 ? "0" + m : m;
            s = s < 10 ? "0" + s : s;

            hour.innerHTML = h;
            minute.innerHTML = m;
            second.innerHTML = s;
        }

        var date6 = new Date('2021-11-30 17:10:20');
        setInterval(() => {
            // var result =
            countDown(date6);
            // console.log(result);
        }, 1000);
    </script>
</body>
</html>